package operation;

import cars.*;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-11-22
 * Time: 17:46
 */
public class RentMgrSys implements IOperation{

    //分层处理过程

    @Override
    public void work(Factory factory) {
        leaseOutFlow(factory);
    }

    public static void leaseOutFlow(Factory factory){
        Scanner scanner = new Scanner(System.in);
        System.out.println("1.轿车  2.客车  3.卡车");
        System.out.print("请选择你要租赁的汽车类型：");
        int choice = scanner.nextInt();
        while (true) {
            if (choice == 1) {
                //汽车处理过程
                carHandle(factory, choice);
                break;
            } else if (choice == 2) {
                //客车处理过程
                busHandle(factory, choice);
                break;
            } else if (choice == 3) {
                //卡车处理过程
                trunkHandle(factory, choice);
                break;
            } else {
                System.out.println("输入错误，请重新输入");
            }
        }
    }

    public static void carHandle(Factory factory, int ch){
        Scanner scanner = new Scanner(System.in);
        System.out.println("1.宝马   2.别克");
        System.out.print("请输入你要租赁的轿车品牌：");
        int choice1 = scanner.nextInt();
        VehicleList carList = factory.getCarList();
        String name = null;
        if (choice1 == 1){
            name = "宝马";
        }else{
            name = "别克";
        }
        //打印对应车辆类型信息
        carList.printf(name);
        System.out.print("请选择你要租赁的轿车型号：");
        int choice2 = scanner.nextInt();
        String type = null;
        if (choice1 == 1){
            if (choice2 == 1){
                type = "550i";
            }else{
                type = "X6";
            }
        }else{
            if (choice2 == 1){
                type = "林荫大道";
            }else{
                type = "GL8";
            }
        }
        System.out.print("请输入您要租赁的天数：");
        int days = scanner.nextInt();
        System.out.print("分配给您的汽车牌号是：");
        //检索到对应车牌号
        Vehicle car = carList.find(name, type);
        System.out.print("您需要支付的租赁费用是：");
        //输出车辆租赁费用
        System.out.println(carList.getPerRent(car, days) + "元。");
    }
    public static void busHandle(Factory factory, int ch){
        Scanner scanner = new Scanner(System.in);
        System.out.println("1.金杯   2.金龙");
        System.out.print("请输入你要租赁的客车品牌：");
        int choice1 = scanner.nextInt();
        VehicleList busList = factory.getBusList();
        String name = null;
        if (choice1 == 1){
            name = "金杯";
        }else{
            name = "金龙";
        }
        busList.printf(name);
        System.out.print("请选择你要租赁的客车座位：");
        int choice2 = scanner.nextInt();
        String type = null;
        if (choice2 == 1){
            type = "16座";
        }else{
            type = "32座";
        }
        System.out.print("请输入您要租赁的天数：");
        int days = scanner.nextInt();
        System.out.print("分配给您的汽车牌号是：");
        Vehicle bus = busList.find(name, type);
        System.out.print("您需要支付的租赁费用是：");
        System.out.println(busList.getPerRent(bus, days) + "元。");
    }
    public static void trunkHandle(Factory factory, int ch){
        Scanner scanner = new Scanner(System.in);
        System.out.println("1.东风   2.雄狮");
        System.out.print("请输入你要租赁的卡车品牌：");
        int choice1 = scanner.nextInt();
        VehicleList trunkList = factory.getTrunkList();
        String name = null;
        if (choice1 == 1){
            name = "东风";
        }else{
            name = "雄狮";
        }
        trunkList.printf(name);
        System.out.print("请选择你要租赁的卡车载重量：");
        int choice2 = scanner.nextInt();
        String type = null;
        if (choice2 == 1){
            type = "6t";
        }else{
            type = "12t";
        }
        System.out.print("请输入您要租赁的天数：");
        int days = scanner.nextInt();
        System.out.print("分配给您的汽车牌号是：");
        Vehicle trunk = trunkList.find(name, type);
        System.out.print("您需要支付的租赁费用是：");
        System.out.println(trunkList.getPerRent(trunk, days) + "元。");
    }
}




























































































